/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Homework6;

import Homework6.CustomEvents.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.*;

/**
 *
 * @author Jakim
 */
class MenuEdit extends Menu {
    // Private fields
    private Vector _listenersSyncList;
    private MenuItem _menuItemCopy;
    private MenuItem _menuItemPaste;
    private MenuItem _menuItemCut;
    private MenuItem _menuItemClear;
    private CheckboxMenuItem _chbMenuItemBold;
    private CheckboxMenuItem _chbMenuItemItalic;
    private char[] bufferCopy;

    // Constructors
    public MenuEdit(){
        super("Edit");

        this._chbMenuItemBold = new CheckboxMenuItem("Bold");
        this._chbMenuItemBold.setName("Bold");
        this._chbMenuItemBold.addItemListener(new ItemListener(){
            public void itemStateChanged(ItemEvent e) {
                EditTextEvent event = new EditTextEvent(e.getSource());
                fireFontChangeListener(event);
            }
        });

        this._chbMenuItemItalic = new CheckboxMenuItem("Italic");
        this._chbMenuItemItalic.setName("Italic");
        this._chbMenuItemItalic.addItemListener(new ItemListener(){

             public void itemStateChanged(ItemEvent e) {
                EditTextEvent event = new EditTextEvent(e.getSource());
                fireFontChangeListener(event);
            }
        });

        this._menuItemCopy = new MenuItem("Copy");
        this._menuItemCopy.setEnabled(false);

        this._menuItemCut = new MenuItem("Cut");
        this._menuItemCut.setEnabled(false);

        this._menuItemPaste = new MenuItem("Paste");
        this._menuItemPaste.setEnabled(false);

        this._menuItemClear = new MenuItem("Clear");
        this._menuItemClear.setEnabled(false);

        this.add(this._menuItemCopy);
        this.add(this._menuItemCut);
        this.add(this._menuItemPaste);
        this.add(this._menuItemClear);
        this.add(this._chbMenuItemBold);
        this.add(this._chbMenuItemItalic);

        this._listenersSyncList = new Vector();
    }

    // Getters
    public CheckboxMenuItem getChbMenuItemBold() {
        return _chbMenuItemBold;
    }

    public CheckboxMenuItem getChbMenuItemItalic() {
        return _chbMenuItemItalic;
    }

    public MenuItem getMenuItemClear() {
        return _menuItemClear;
    }

    public MenuItem getMenuItemCopy() {
        return _menuItemCopy;
    }

    public MenuItem getMenuItemCut() {
        return _menuItemCut;
    }

    public MenuItem getMenuItemPaste() {
        return _menuItemPaste;
    }

    // Events
    public void addFontChangeListener(IEditTextListener listener){
        this._listenersSyncList.add(listener);
    }

    public void removeFontChangeListener(IEditTextListener listener){
        this._listenersSyncList.remove(listener);
    }

    private void fireFontChangeListener(EditTextEvent e){
        Iterator itr = this._listenersSyncList.iterator();
        while(itr.hasNext()) {
            ((IEditTextListener)itr.next()).penChangeFontOcured(e);
      }
    }
}
